﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin
{
    public class Menu
    {
        public MenuCon MenuTopic { get; set; }
        public List<MenuCon> ListMenuSon { get { return _ListMenuSon; } set { _ListMenuSon = value; } }
        private List<MenuCon> _ListMenuSon = new List<MenuCon>();
        public Menu(MenuCon MenuTopic_, List<MenuCon> ListMenuSon_) { MenuTopic = MenuTopic_; _ListMenuSon = ListMenuSon_; }
    }
    public class MenuCon
    {
        public string Href { get { return _Href; } set { _Href = value; } }
        private string _Href = "";
        public string Html { get { return _Html; } set { _Html = value; } }
        private string _Html = "";
        public string Title { get { return _Title; } set { _Title = value; } }
        private string _Title = "";
        public bool IsHrefRight { get { return _IsHrefRight; } set { _IsHrefRight = value; } }
        private bool _IsHrefRight = false;
        public MenuCon(string href_, string html_)
        {
            _Href = href_; _Html = html_; _Title = html_;
        }
        public MenuCon(string href_, string html_, string title_)
        {
            _Href = href_; _Html = html_; _Title = title_;
        }
        public MenuCon(string href_, string html_, bool isHrefRight_)
        {
            _Href = href_; _Html = html_; _Title = html_; _IsHrefRight = isHrefRight_;
        }
        public MenuCon(string href_, string html_, string title_, bool isHrefRight_)
        {
            _Href = href_; _Html = html_; _Title = title_; _IsHrefRight = isHrefRight_;
        }
    }
    public partial class Default : System.Web.UI.Page
    {
        BLL.Orders bllOrders = new BLL.Orders();
        BLL.Orders_Goods bllOrdersGoods = new BLL.Orders_Goods();
        BLL.Draw bllDraw = new BLL.Draw();
        BLL.Goods bllGoods = new BLL.Goods();
        BLL.V_Supplier bllV_Supplier = new BLL.V_Supplier();
        BLL.V_Store bllV_Store = new BLL.V_Store();
        BLL.Goods_BuyPrice_Log bllGoods_BuyPrice_Log = new BLL.Goods_BuyPrice_Log();
        BLL.Goods_SellPrice_Log bllGoods_SellPrice_Log = new BLL.Goods_SellPrice_Log();
        protected int Count_ApplyDraw_Wait = 0, Count_Goods_WaitCheck = 0, Count_Supplier_WaitCheck = 0, Count_Store_WaitCheck = 0, Count_BuyPrice_Log_WaitRead = 0, Count_SellPrice_Log_WaitRead = 0, Count_Store_PAFeeEndDate=0;
        protected int Count_Orders_Goods_WaitMoney = 0;
        protected int Count_Supplier_will_sell = 0, Count_Supplier_Delivery_waitChcek = 0, Count_Supplier_Delivery_hasChcek=0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Security.IsLogined()) buildDom_login();
                else buildDom_logout();
                //
                
            }
        }

        protected void bt_submit_Click(object sender, EventArgs e)
        {
            string username = DataTypePlus.requestString(tb_username.Text);
            string password = DataTypePlus.requestString(tb_password.Text);
            if (username == "" || password == "") ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('登陆账号和密码都需要填写');Dom_Login(); ", true);
            {
                CallBak<int> LoginUser=Security.CHKlogin(username, password);
                if(!LoginUser.IsSuccess) ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('"+LoginUser.ErrMsg+"'); Dom_Login();", true);
                else buildDom_login();
            }
        }

        protected void bt_logOut_Click(object sender, EventArgs e)
        {
            UserType_Store.Visible = false;
            UserType_Admin.Visible = false;
            //
            Security.Logout();
            buildDom_logout();
        }
        void buildDom_login()
        {
            timer_Public.Enabled = true;

            div_default.Visible = true;
            div_login.Visible = false;

            List<Menu> ListMenu = new List<Menu>();
            switch (Security.GetCurrentUserType())
            {
                case EnumHelper.UserType.EntryPerson://录入员
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/goods/list.aspx?istopsearch=1", "商品", "所有商品"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/goods/list.aspx?istopsearch=1", "全部") ,
                            new MenuCon("/sys/category/list.aspx", "分类") ,
                            new MenuCon("/sys/brand/list.aspx", "品牌"),
                            new MenuCon("/sys/User_Operate_Log/list.aspx?type=entry", "操作日志"),
                            }));
                    ListMenu.Add(new Menu(
                       new MenuCon("/sys/setting/default.aspx", "设置"),
                       new List<MenuCon>() { }));
                    break;
                    #endregion
                case EnumHelper.UserType.Administrator://管理员
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/goods/list.aspx?istopsearch=1", "商品", "所有商品"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/goods/list.aspx?istopsearch=1", "全部") ,
                            new MenuCon("/sys/category/list.aspx", "分类") ,
                            new MenuCon("/sys/brand/list.aspx", "品牌") 
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/supplier/list.aspx", "联盟商家", "供货商"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/supplier/list.aspx", "供货商") ,
                            new MenuCon("/sys/store/list.aspx", "孕婴店"),
                            new MenuCon("/sys/account_change_log/list.aspx", "账户收支"),
                            new MenuCon("/sys/applydraw/list.aspx", "提款申请"),
                            new MenuCon("/sys/draw/list.aspx", "提款记录"),
                            new MenuCon("/sys/pafee/list.aspx", "联盟费记录")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/orders/list.aspx", "订单", "全部订单"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/orders/list.aspx", "全部","全部订单") ,
                            new MenuCon("/sys/orders/will/list.aspx", "<i class=\"fa fa-calendar\"></i>预计", "预计产生的订单") ,
                            new MenuCon("/sys/orders/money/list.aspx", "<i class=\"fa fa-cny\"></i>收货款","今日待收款订单") ,
                            new MenuCon("/sys/orders/call4delivery/list.aspx", "<i class=\"fa fa-bullhorn\"></i>通知送货","通知供货商送货"),
                            new MenuCon("/sys/orders/getmoney/list.aspx", "<i class=\"fa fa-money\"></i>预支", "准备采购并等待预支的订单") ,
                            new MenuCon("/sys/orders/receive/list.aspx", "<i class=\"fa fa-shopping-cart\"></i>待收货","等待供货商送货的订单"),
                            new MenuCon("/sys/orders/receive/tg_List.aspx", "<i class=\"fa fa-shopping-cart\"></i>团购待收货","等待供货商送货的订单"),
                            new MenuCon("/sys/orders/buying/list.aspx?isdelivery=0", "<i class=\"fa fa-shopping-cart\"></i>采购","正在采购的订单"),
                            new MenuCon("/sys/orders/getmoney/checkorderlist.aspx", "<i class=\"fa fa-money\"></i>订单核对","核对已采购的订单") ,
                            new MenuCon("/sys/orders/pause/list.aspx", "<i class=\"fa fa-pause\"></i>暂停","暂停采购的订单"),
                            new MenuCon("/sys/orders/buyfinish/list.aspx", "<i class=\"fa fa-truck\"></i>发货", "待发货的订单") ,
                            new MenuCon("/sys/orders/hassend_today/list.aspx", "<i class=\"fa fa-check\"></i>今日完成","今天完成订单") ,
                            new MenuCon("/sys/orders/buymoneyfail_receive/list.aspx", "<i class=\"fa fa-money\"></i>清算收货款", "清算需要退补收货款的订单") ,
                            new MenuCon("/sys/orders/buymoneyfail/list.aspx", "<i class=\"fa fa-money\"></i>清算采购款", "需要退补采购款的订单") ,
                            new MenuCon("/sys/orders/history/list.aspx", "<i class=\"fa fa-clock-o\"></i>历史", "已完成历史订单") ,
                            new MenuCon("/sys/express/list.aspx", "物流")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/buyer/list.aspx", "工作人员", "采购员"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/EntryPerson/list.aspx", "录入员"),
                            new MenuCon("/sys/buyer/list.aspx", "采购员"),
                            new MenuCon("/sys/receiver/list.aspx", "收货员"),
                            new MenuCon("/sys/accountant/list.aspx", "财务员") ,
                            new MenuCon("/sys/storeserver/list.aspx", "孕婴店管理员") ,
                            new MenuCon("/sys/supplierserver/list.aspx", "供货商管理员") ,
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/Group_Buy/Good_List.aspx", "团购", "团购"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/Group_Buy/Good_List.aspx", "新建团购"),
                            new MenuCon("/sys/Group_Buy/list.aspx", "团购管理"),
                            new MenuCon("/sys/Group_Buy/history_list.aspx", "历史团购"),
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/message/list_send.aspx", "通知", "已发通知"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/message/list_send.aspx", "已发通知"),
                            new MenuCon("/sys/message/list_receive.aspx", "收到的通知"),
                            new MenuCon("/sys/message/Config_Set.aspx", "信息管理"),
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/User_Operate_Log/list.aspx", "操作历史"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/setting/default.aspx", "设置"),
                        new List<MenuCon>() { }));
                    //
                    lb_Username.Text = "管理员";
                    break;
                    #endregion
                case EnumHelper.UserType.StoreServer://孕婴店管理员
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/store/list.aspx", "孕婴店"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/store/list.aspx", "孕婴店"),
                            new MenuCon("/sys/Account_Change_Log/list.aspx", "账户收支")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/message/list_send.aspx", "通知", "已发通知"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/message/list_send.aspx", "已发通知"),
                            new MenuCon("/sys/message/list_receive.aspx", "收到的通知")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/storeserver/setting/default.aspx", "设置"),
                        new List<MenuCon>() { }));
                    break;
                    #endregion
                case EnumHelper.UserType.SupplierServer://供货商管理员
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/goods/list.aspx?istopsearch=1", "商品", "所有商品"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/goods/list.aspx?istopsearch=1", "全部") ,
                            new MenuCon("/sys/category/list.aspx", "分类") ,
                            new MenuCon("/sys/brand/list.aspx", "品牌") 
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/supplier/list.aspx", "供货商"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/supplier/list.aspx", "供货商") ,
                            new MenuCon("/sys/Account_Change_Log/list.aspx", "账户收支")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/message/list_send.aspx", "通知", "已发通知"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/message/list_send.aspx", "已发通知"),
                            new MenuCon("/sys/message/list_receive.aspx", "收到的通知")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/supplierserver/setting/default.aspx", "设置"),
                        new List<MenuCon>() { }));
                    break;
                    #endregion
                case EnumHelper.UserType.Accountant://财务员
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/orders/money/list.aspx", "订单", "今日收款订单"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/orders/money/list.aspx", "<i class=\"fa fa-cny\"></i>收货款","今日收款订单") ,
                            new MenuCon("/sys/orders/getmoney/list.aspx", "<i class=\"fa fa-money\"></i>预支","准备采购并等待预支的订单") ,
                            new MenuCon("/sys/orders/getmoney/checkorderlist.aspx", "<i class=\"fa fa-money\"></i>订单核对","核对已采购的订单") ,
                            new MenuCon("/sys/orders/buymoneyfail_delivery/list.aspx", "<i class=\"fa fa-money\"></i>清算收货款", "清算需要退补收货款的订单") ,
                            new MenuCon("/sys/orders/buymoneyfail/list.aspx", "<i class=\"fa fa-money\"></i>清算采购款", "清算需要退补采购款的订单") ,
                            new MenuCon("/sys/orders/hassend_today/list.aspx", "<i class=\"fa fa-check\"></i>今日完成","今天完成订单") ,
                            new MenuCon("/sys/orders/history/list.aspx", "<i class=\"fa fa-clock-o\"></i>历史", "已完成历史订单") ,
                            new MenuCon("/sys/orders/list.aspx", "全部","全部订单") 
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/supplier/list.aspx", "商家账户", "供货商"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/supplier/list.aspx", "供货商") ,
                            new MenuCon("/sys/store/list.aspx", "孕婴店"),
                            new MenuCon("/sys/account_change_log/list.aspx", "收支记录"),
                            new MenuCon("/sys/applydraw/list.aspx", "提款申请"),
                            new MenuCon("/sys/draw/list.aspx", "提款记录"),
                            new MenuCon("/sys/pafee/list.aspx", "联盟费记录")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/message/list_receive.aspx", "通知"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/accountant/setting/default.aspx", "设置"),
                        new List<MenuCon>() { }));
                    break;
                    #endregion
                case EnumHelper.UserType.Buyer://采购员
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/orders/buying/list.aspx", "订单", "收到新的订单"),
                        new List<MenuCon>() { 
                            //new MenuCon("/sys/orders/will/list.aspx", "<i class=\"fa fa-calendar\"></i>预计", "预计产生的订单") ,
                            //new MenuCon("/sys/orders/getmoney/list.aspx", "<i class=\"fa fa-tasks\"></i>收单","收到新的订单") ,
                            //new MenuCon("/sys/orders/readybuy/list.aspx", "<i class=\"fa fa-money\"></i>准备采购", "准备采购并等待打款的订单") ,
                            new MenuCon("/sys/orders/buying/list.aspx", "<i class=\"fa fa-shopping-cart\"></i>采购", "正在采购的订单") ,
                            new MenuCon("/sys/orders/pause/list.aspx", "<i class=\"fa fa-pause\"></i>暂停","暂停采购的订单"),
                            new MenuCon("/sys/orders/buyfinish/list.aspx", "<i class=\"fa fa-truck\"></i>发货", "等待发货的订单") ,
                            new MenuCon("/sys/orders/buymoneyfail/list.aspx", "<i class=\"fa fa-money\"></i>清算采购款", "清算需要退补采购款的订单") ,
                            new MenuCon("/sys/orders/hassend_today/list.aspx", "<i class=\"fa fa-check\"></i>今日完成","今天完成订单") ,
                            new MenuCon("/sys/orders/history/list.aspx", "<i class=\"fa fa-clock-o\"></i>历史", "已完成历史订单") ,
                            new MenuCon("/sys/orders/list.aspx", "全部","全部订单")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/express/list.aspx", "物流"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/goods/list.aspx?istopsearch=1", "商品", "所有商品"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/goods/list.aspx?istopsearch=1", "全部") ,
                            new MenuCon("/sys/category/list.aspx", "分类") ,
                            new MenuCon("/sys/brand/list.aspx", "品牌") 
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/supplier/list.aspx", "联盟商家", "供货商"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/supplier/list.aspx", "供货商") ,
                            new MenuCon("/sys/store/list.aspx", "孕婴店")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/message/list_receive.aspx", "通知"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/buyer/setting/default.aspx", "设置"),
                        new List<MenuCon>() { }));
                    break;
                    #endregion
                case EnumHelper.UserType.Receiver://收货员
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/orders/call4delivery/list.aspx", "订单", "等待供货商送货的订单"),
                        new List<MenuCon>() { 
                            new MenuCon("/sys/orders/call4delivery/list.aspx", "<i class=\"fa fa-bullhorn\"></i>通知送货","通知供货商送货"),
                            new MenuCon("/sys/orders/receive/list.aspx", "<i class=\"fa fa-shopping-cart\"></i>待收货","等待供货商送货的订单"),
                            new MenuCon("/sys/orders/buymoneyfail_receive/list.aspx", "<i class=\"fa fa-money\"></i>清算收货款", "清算需要退补收货款的订单") ,
                            new MenuCon("/sys/orders/history/list.aspx", "<i class=\"fa fa-clock-o\"></i>历史", "已完成历史订单")
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/message/list_receive.aspx", "通知"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/buyer/setting/default.aspx", "设置"),
                        new List<MenuCon>() { }));
                    break;
                    #endregion
                case EnumHelper.UserType.Supplier://供货商
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/goods/list.aspx?istopsearch=1", "商品", "我的所有商品"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/supplier/orders_goods/delivery/list_waitcheck.aspx", "点货", "等待点货的商品"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/supplier/orders_goods/delivery/list_hascheck.aspx", "已点货", "今天已点货商品"),
                        new List<MenuCon>() { }));
                    //ListMenu.Add(new Menu(
                    //    new MenuCon("/sys/Goods_Stat/list.aspx", "销售统计"),
                    //    new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/Account_Change_Log/list.aspx", "账户收支"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/draw/list.aspx", "提款记录"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/message/list_receive.aspx", "通知"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/supplier/setting/default.aspx", "设置"),
                        new List<MenuCon>() { }));
                    break;
                    #endregion
                case EnumHelper.UserType.Store://孕婴店
                    #region
                    ListMenu.Add(new Menu(
                        new MenuCon("/store/goods/first.aspx", "首页", "首页"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/store/goods/list.aspx?istopsearch=1", "商品", "所有商品"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/brand/list.aspx", "品牌", "所有品牌"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                          new MenuCon("/Store/Group_Buy/Group_List.aspx", "团购", "团购"),
                          new List<MenuCon>() { 
                            new MenuCon("/Store/Group_Buy/Group_List.aspx", "团购列表"),
                            new MenuCon("/Store/Group_Buy/History_List.aspx", "历史团购"),
                            }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/store/orders/form.aspx", "本周订单", true),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/store/orders/list.aspx", "历史订单"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/Account_Change_Log/list.aspx", "账户收支"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/draw/list.aspx", "提款记录"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/pafee/list.aspx", "联盟费记录"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/supplier/list.aspx", "供应商"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/sys/message/list_receive.aspx", "通知"),
                        new List<MenuCon>() { }));
                    ListMenu.Add(new Menu(
                        new MenuCon("/store/setting/default.aspx", "设置"),
                        new List<MenuCon>() { }));
                    //
                    break;
                    #endregion
            }
            BBPA.BLL.Config c = new BBPA.BLL.Config();
            DataTable dt = c.GetList(" ModelName='infomsg'").Tables[0];
            logo1.InnerHtml = dt.Rows[0]["Data"].ToString();
            lb_Username.Text = Security.GetCurrentName();
            if (Security.GetCurrentUserType() != EnumHelper.UserType.Administrator)
            {
                span_Number.Visible = true;
                lb_Number.Text = Security.GetCurrentNumber();
            }
            else span_Number.Visible = false;
            rp_Menu.DataSource = ListMenu;
            rp_Menu.DataBind();
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "Dom_Default(); ", true);
        }
        protected void rp_Menu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rp_ListMenuSon = (Repeater)e.Item.FindControl("rp_ListMenuSon");
                Menu thisMenu = (Menu)e.Item.DataItem;
                rp_ListMenuSon.DataSource = thisMenu.ListMenuSon;
                rp_ListMenuSon.DataBind();
            }
        }
        void buildDom_logout()
        {
            timer_Public.Enabled = false;
            tb_SMSid_readed.Text = "0";

            tb_username.Text = "";
            div_default.Visible = false;
            div_login.Visible = true;
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "Dom_Login(); ", true);
        }

        

        protected void bt_SMSid_setState1_Click(object sender, EventArgs e)
        {
            //DAO.SMS.Model.SMSModel modelSMS = bllSMS.GetSMSModelByID(DataTypePlus.requestInt(tb_SMSid_setState1.Text));
            //if (modelSMS != null)
            //{
            //    modelSMS.State = 1;
            //    bllSMS.EditSMS(modelSMS);
            //}
            BBPA.BLL.Message.SetHasRead(DataTypePlus.requestInt(tb_SMSid_setState1.Text), Security.GetCurrentUser());
        }

       

        
        protected void timer_Public_Tick(object sender, EventArgs e)
        {
            Update_Timer1_Con();
        }
        protected void bt_Timer1_Click(object sender, EventArgs e)
        {
            Update_Timer1_Con();
        }
        void Update_Timer1_Con()
        {

            string sql_Message = "(";
            sql_Message += "(ReceiveUserID>0 and ReceiveUserID=" + Security.GetCurrentUserID() + ")"; //id
            sql_Message += " or (ReceiveUserIDStr<>'' and ','+ReceiveUserIDStr+',' like '%," + Security.GetCurrentUserID() + ",%')";//;idstr
            sql_Message += " or (ReceiveUserTypeID>0 and ReceiveUserTypeID=" + (int)Security.GetCurrentUserType() + ")";//用户类
            sql_Message += " or (ReceiveUserID=0 and ReceiveUserIDStr='' and ReceiveUserTypeID=0)";//全部
            sql_Message += ")";
            sql_Message += " and ID>" + DataTypePlus.requestInt(tb_SMSid_readed.Text);
            sql_Message += " and charindex(','+CAST(id  AS VARCHAR(20))+',',','+(select UnReadMessageIDStr from PAUser where id=" + Security.GetCurrentUserID() + ")+',')>0";
            BLL.V_Message bllMessage = new BLL.V_Message();
            List<Model.V_Message> listMessage = bllMessage.GetModelList(sql_Message);
            if (listMessage.Count > 0)
            {
                tb_SMSid_readed.Text = listMessage[listMessage.Count - 1].id.ToString();
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "NewSMS(" + StringPlus.Object2Json4Js(listMessage) + "); ", true);
            }
            //
            switch (Security.GetCurrentUserType())
            {
                case EnumHelper.UserType.Administrator:
                    Count_ApplyDraw_Wait = bllDraw.GetRecordCount("State=" + (int)EnumHelper.DrawState.Wait);
                    Count_Goods_WaitCheck = bllGoods.GetRecordCount("State=" + (int)EnumHelper.GoodsState.WaitCheck);
                    Count_Supplier_WaitCheck = bllV_Supplier.GetRecordCount("State=" + (int)EnumHelper.UserState.WaitCheck);
                    Count_Store_WaitCheck = bllV_Store.GetRecordCount("State=" + (int)EnumHelper.UserState.WaitCheck);
                    Count_BuyPrice_Log_WaitRead = bllGoods_BuyPrice_Log.GetRecordCount("HasRead=0");
                    Count_SellPrice_Log_WaitRead = bllGoods_SellPrice_Log.GetRecordCount("HasRead=0");
                    Count_Store_PAFeeEndDate = bllV_Store.GetRecordCount("PAFeeEndDate<getdate()");
                    UserType_Admin.Visible = true;
                    break;
                case EnumHelper.UserType.Store:
                    int StoreID = Security.GetCurrentStoreID();
                    Count_Orders_Goods_WaitMoney = bllOrdersGoods.GetRecordCount("OrdersID in (select id from Orders where StoreID=" + StoreID + " and State=" + (int)EnumHelper.OrdersState.WaitMoney + ")");
                    UserType_Store.Visible = true;
                    break;
                case EnumHelper.UserType.Supplier:
                    Count_Supplier_will_sell = bllGoods.GetRecordCount("SupplierID=" + Security.GetCurrentSupplierID() + " and id in(select GoodsID from Orders_Goods where HasBuy=0  and WaitSupplierCheckNum>0)");
                    //
                    //string sql_orders_goods_waitCheck = "HasBuy=0 and WaitSupplierCheckNum>0 and HasCheck=0 and OrdersID in(select id from V_Orders where (State=" + (int)EnumHelper.OrdersState.GetMoney + " or State=" + (int)EnumHelper.OrdersState.Buying + " ) and FirstExpectBuyDate is not null and datediff(day,FirstExpectBuyDate,getdate())>=0 )";
                    string sql_orders_goods_waitCheck = "HasBuy=0 and WaitSupplierCheckNum>0 and HasCheck=0 and OrdersID in(select id from V_Orders where (State=" + (int)EnumHelper.OrdersState.GetMoney + " or State=" + (int)EnumHelper.OrdersState.Buying + " )  )";
                    Count_Supplier_Delivery_waitChcek = bllGoods.GetRecordCount("id in (select GoodsID from Orders_Goods where " + sql_orders_goods_waitCheck + ") and  SupplierID=" + Security.GetCurrentSupplierID());
                    //string sql_orders_goods_hasCheck = "HasBuy=0 and WaitSupplierCheckNum>0 and HasCheck=1 and OrdersID in(select id from V_Orders where (State=" + (int)EnumHelper.OrdersState.GetMoney + " or State=" + (int)EnumHelper.OrdersState.Buying + " ) and FirstExpectBuyDate is not null and datediff(day,FirstExpectBuyDate,getdate())>=0 )";
                    string sql_orders_goods_hasCheck = "HasBuy=0 and WaitSupplierCheckNum>0 and HasCheck=1 and OrdersID in(select id from V_Orders where (State=" + (int)EnumHelper.OrdersState.GetMoney + " or State=" + (int)EnumHelper.OrdersState.Buying + " ) )";
                    Count_Supplier_Delivery_hasChcek = bllGoods.GetRecordCount("id in (select GoodsID from Orders_Goods where " + sql_orders_goods_waitCheck + ") and  SupplierID=" + Security.GetCurrentSupplierID());
                    
                    UserType_Supplier.Visible = true;
                    break;
            }
            //
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "bindEvent_href($('#me_info')); ", true);
            //
        }
    }
}